---
title: "Discordant_MTPS"
author: "Edmund Kelly"
date: "2023-04-17"
output: html_document
---
```{r, setup}

knitr::opts_knit$set(root.dir = "C:/Users/edmun/Documents/2023-2026 - DPhil Politics/2 - OTHER PAPERS/2 - UNDER REVIEW/UR - Twins and trust/Replication materials/Minnesota")

setwd("C:/Users/edmun/Documents/2023-2026 - DPhil Politics/2 - OTHER PAPERS/2 - UNDER REVIEW/UR - Twins and trust/Replication materials/Minnesota")


```

```{r Packages, echo = FALSE} 
library(OpenMx)
library(umx) 
library(haven)
library(tidyverse)
library(stargazer)
library(eeptools)
library(sjPlot)
library(ggplot2)
library(broom)
library(RColorBrewer)
library(psych)
library(fixest)
library(ggh4x)
library(ggpubr)
library(psychTools)
library(modelsummary)
set.seed(1234)
```

```{r Pre-Processing, echo = FALSE}

MTPS_orig <- data.frame(read_spss("MTPS.sav"))

#Equal environment variables

MTPS_orig$bedroom = as.numeric(MTPS_orig$Qq73_A_1)
MTPS_orig$dressalike = as.numeric(MTPS_orig$Qq73_A_3)
MTPS_orig$sameclass = as.numeric(MTPS_orig$Qq73_A_4)
MTPS_orig$samefriends = as.numeric(MTPS_orig$Qq73_A_2)

#Turnout

MTPS_orig$turnout04 <- as.numeric(MTPS_orig$Qq39)

MTPS_orig$turnout04_scaled = scale(MTPS_orig$turnout04)

MTPS_orig <- MTPS_orig %>% mutate(turnout04 = 
                          dplyr::recode(turnout04, 
                                 "1" = 1,
                                 "2" = 0, 
                                 "3" = 0))

MTPS_orig$lifeturnout <- (6-MTPS_orig$Qq41)/5 

MTPS_orig$lifeturnout = ifelse(MTPS_orig$lifeturnout == 1, 1, 0)

MTPS_orig$overallturnout = (MTPS_orig$lifeturnout + MTPS_orig$turnout04)/2

MTPS_orig$overallturnout_scaled = scale(MTPS_orig$overallturnout)


#Behavioral engagement

MTPS_orig$group = as.factor(MTPS_orig$Qq44)
MTPS_orig = MTPS_orig %>% mutate(group = 
                                   dplyr::recode(group, 
                                                 "1" = 1, 
                                                 "2" = 0.5, 
                                                 "3" = 0))

MTPS_orig$rally <- as.factor(MTPS_orig$Qq43_A_1)
MTPS_orig <- MTPS_orig %>% mutate(rally = 
                          dplyr::recode(rally, 
                                 "1" = 1,
                                 "2" = 0))

MTPS_orig$workpol <- as.factor(MTPS_orig$Qq43_A_2)
MTPS_orig <- MTPS_orig %>% mutate(workpol = 
                          dplyr::recode(workpol, 
                                 "1" = 1,
                                 "2" = 0))

MTPS_orig$donate <- as.factor(MTPS_orig$Qq43_A_3)
MTPS_orig <- MTPS_orig %>% mutate(donate = 
                         dplyr::recode(donate, 
                                 "1" = 1,
                                 "2" = 0))

MTPS_orig$discusspol <- as.factor(MTPS_orig$Qq46)
MTPS_orig <- MTPS_orig %>% mutate(discusspol = 
                         dplyr::recode(discusspol, 
                                 "1" = 1,
                                 "2" = 0.67, 
                                 "3" = 0.33, 
                                 "4" = 0))

MTPS_orig$writepol <- as.factor(MTPS_orig$Qq43_A_5)
MTPS_orig <- MTPS_orig %>% mutate(writepol = 
                          dplyr::recode(writepol, 
                                 "1" = 1,
                                 "2" = 0))


MTPS_orig$newsum = (MTPS_orig$donate + MTPS_orig$rally + MTPS_orig$workpol + MTPS_orig$writepol)

MTPS_orig$behavioral <- scale(MTPS_orig$newsum)
MTPS_orig$Behavioral <- (MTPS_orig$newsum)/4

#Political trust

MTPS_orig$trustgov <- ((3-MTPS_orig$Qq28))/2

MTPS_orig$trustbiginterest <- (MTPS_orig$Qq29-1)

MTPS_orig$trustpol <- (MTPS_orig$Qq31-1)/2

MTPS_orig$wastetax <- (MTPS_orig$Qq30-1)/2

MTPS_orig$trustgov_scaled = scale(MTPS_orig$trustgov)

MTPS_orig$trustpol_scaled = scale(MTPS_orig$trustpol)

MTPS_orig$trustbiginterest_scaled = scale(MTPS_orig$trustbiginterest)

MTPS_orig$wastetax_scaled = scale(MTPS_orig$wastetax)

MTPS_orig$newtrust = (MTPS_orig$trustgov + MTPS_orig$trustbiginterest + MTPS_orig$trustpol + MTPS_orig$wastetax)/4

MTPS_orig$trust <- scale(MTPS_orig$newtrust) 

MTPS_orig$gentrust = MTPS_orig$Qq27

#Creating twin variables

MTPS_orig$FAMID <- as.factor(MTPS_orig$FAMID)

MTPS_orig$BDATE <- as.Date(MTPS_orig$BDATE)
a = as.Date(c('2024-10-04'))
MTPS_orig$AGE <- floor(age_calc(as.Date(MTPS_orig$BDATE), enddate = a, units = "years", precise = TRUE)) - 14
MTPS_orig$AGE_factor = as.factor(MTPS_orig$AGE)
MTPS_orig_MZ <- subset(MTPS_orig, ZYG == 1)
MTPS_orig_DZ <- subset(MTPS_orig, ZYG == 2)

```

```{r Appendix 4: Phenotype correlations table}

# create empty data frame to store results
corr_df <- data.frame(
  "Trust" = character(),
  "Variable" = character(),
  "Correlation" = numeric(),
  "95% CI" = character(),
  stringsAsFactors = FALSE
)

# iterate over variables

trust_vars <- c("trust")
for (trust_var in trust_vars) {
  vars <- c("behavioral", "overallturnout")

for (var in vars) {
  
  # run correlation test
  corr_test <- cor.test(MTPS_orig[[trust_var]], MTPS_orig[[var]], method = "pearson", 
                         use = "pairwise.complete.obs")
  
  # extract values
  cor_coef <- round(corr_test$estimate, digits = 2)
  ci_lower <- corr_test$conf.int[1]
  ci_upper <- corr_test$conf.int[2]
  
  # add results to data frame
  corr_df <- rbind(corr_df, data.frame(
    "Trust" = trust_var,
    "Variable" = var,
    "Correlation" = cor_coef,
    "95% CI" = paste0("(", sprintf("%.2f", ci_lower), ", ", sprintf("%.2f", ci_upper), ")")
  ))
}
}

View(corr_df)

```

```{r Appendix 3: Descriptive statistics}

MTPS_orig_MZ %>% 
  select(AGE, ZYG, rsex, starts_with("trust"), starts_with("wastetax"), newtrust, bedroom, dressalike, sameclass, samefriends, turnout04, lifeturnout, overallturnout, Behavioral, donate, workpol, rally, writepol) %>% 
  as.data.frame() %>% 
  stargazer(iqr = T, median = T, out = "MTPS_discordant_summary_MZ.htm")

MTPS_orig_DZ %>% 
  select(AGE, ZYG, rsex, starts_with("trust"), starts_with("wastetax"), newtrust, bedroom, dressalike, sameclass, samefriends, turnout04, lifeturnout, overallturnout, Behavioral, donate, workpol, rally, writepol) %>%   as.data.frame() %>% 
  stargazer(iqr = T, median = T, out = "MTPS_discordant_summary_DZ.htm")

```

```{r Appendix 1: factor analysis trust}

MTPS_orig %>% 
  select("trustpol", "trustgov", "trustbiginterest", "wastetax") %>% 
  psych::alpha() 

MTPS_orig_FA = MTPS_orig %>% 
  select("trustpol", "trustgov", "trustbiginterest", "wastetax") %>% 
  na.omit() %>% 
  fa(rotate = "varimax")

fa2latex(MTPS_orig_FA)

Variable = c("Trust in politicians", "Trust in government", "Big interest", "Waste tax")
Loading = c(0.55, 0.65, 0.70, 0.50)
"Var" = c("Percentage of variance", 0.37)
"Alpha" = c("Alpha", 0.69)

factor_trust = data.frame(cbind(Variable, Loading)) %>% 
  rbind(Var) %>% 
  rbind(Alpha) 

stargazer(factor_trust, type = "latex")

```

```{r Models for Appendix Tables A3e, A3f, A3i, A3k and A3l}

###Behavioral engagement

#Trust in government
be_1 <- lm(behavioral ~ trustgov_scaled + AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_MZ)

be_1FE <- lm(behavioral ~ trustgov_scaled + FAMID, data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
be_2 <- lm(behavioral ~ trustpol_scaled + AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_MZ)

be_2FE <- lm(behavioral ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
be_3 <- lm(behavioral ~ wastetax_scaled+ AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_MZ)

be_3FE <- lm(behavioral ~ wastetax_scaled + FAMID, data = MTPS_orig_MZ)

#Big interest
be_4 <- lm(behavioral ~ trustbiginterest_scaled+ AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_MZ)

be_4FE <- lm(behavioral ~ trustbiginterest_scaled + FAMID, data = MTPS_orig_MZ)

#Trust
be_5 <- lm(behavioral ~ trust + AGE_factor + AGE_factor*rsex+ rsex, data = MTPS_orig_MZ)

be_5FE <- lm(behavioral ~ trust + FAMID, data = MTPS_orig_MZ)

#Trust_DZ
be_5_DZ <- lm(behavioral ~ trust + AGE_factor + AGE_factor*rsex + rsex , data = MTPS_orig_DZ)

be_5FE_DZ <- lm(behavioral ~ trust + FAMID, data = MTPS_orig_DZ)


###Turnout

#Trust in government
tu_1 <- lm(overallturnout_scaled ~ trustgov_scaled + AGE_factor + AGE_factor*rsex + rsex , data = MTPS_orig_MZ)

tu_1FE <- lm(overallturnout_scaled ~ trustgov_scaled + FAMID, data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
tu_2 <- lm(overallturnout_scaled ~ trustpol_scaled + AGE_factor + AGE_factor*rsex+ rsex , data = MTPS_orig_MZ)

tu_2FE <- lm(overallturnout_scaled ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
tu_3 <- lm(overallturnout_scaled ~ wastetax_scaled + AGE_factor + AGE_factor*rsex+ rsex, data = MTPS_orig_MZ)

tu_3FE <- lm(overallturnout_scaled ~ wastetax_scaled + FAMID, data = MTPS_orig_MZ)

#Big interest
tu_4 <- lm(overallturnout_scaled ~ trustbiginterest_scaled + AGE_factor + AGE_factor*rsex+ rsex, data = MTPS_orig_MZ)

tu_4FE <- lm(overallturnout_scaled ~ trustbiginterest_scaled + FAMID, data = MTPS_orig_MZ)

#Trust
tu_5 <- lm(overallturnout_scaled ~ trust + AGE_factor + AGE_factor*rsex + rsex , data = MTPS_orig_MZ)

tu_5FE <- lm(overallturnout_scaled ~ trust + FAMID, data = MTPS_orig_MZ)

#Trust_DZ
tu_5_DZ <- lm(overallturnout_scaled ~ trust + AGE_factor + AGE_factor*rsex + rsex , data = MTPS_orig_DZ)

tu_5FE_DZ <- lm(overallturnout_scaled ~ trust + FAMID, data = MTPS_orig_DZ)


```

```{r Appendix Tables A3e and A3f}

stargazer(be_5, be_5FE, tu_5, tu_5FE, type = "text", omit = c("FAMID"), out = "Discordant_headline.htm",dep.var.labels = c("Behavioral scale", "Turnout scale"))

stargazer(be_5_DZ, be_5FE_DZ, tu_5_DZ, tu_5FE_DZ, type = "text", omit = c("FAMID"), out = "Discordant_headline_DZ.htm",dep.var.labels = c("Behavioral scale", "Turnout scale"))

```

```{r Appendix Tables A3i and A3k}

stargazer(be_1, be_1FE, be_2, be_2FE, be_3, be_3FE, be_4, be_4FE, be_5, be_5FE, type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behavioral.htm", dep.var.labels = "Behavioral scale")

stargazer(tu_1, tu_1FE, tu_2, tu_2FE, tu_3, tu_3FE, tu_4, tu_4FE, tu_5, tu_5FE, type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Turnout.htm",  dep.var.labels = "Turnout scale")

```

```{r Models for Appendix Tables A3j and A3l}

###Behavioral engagement

#Trust in government
be_1 <- lm(behavioral ~ trustgov_scaled + AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_DZ)

be_1FE <- lm(behavioral ~ trustgov_scaled + FAMID, data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
be_2 <- lm(behavioral ~ trustpol_scaled + AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_DZ)

be_2FE <- lm(behavioral ~ trustpol_scaled + FAMID, data = MTPS_orig_DZ)

#Waste taxes
be_3 <- lm(behavioral ~ wastetax_scaled+ AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_DZ)

be_3FE <- lm(behavioral ~ wastetax_scaled + FAMID, data = MTPS_orig_DZ)

#Big interest
be_4 <- lm(behavioral ~ trustbiginterest_scaled+ AGE_factor + AGE_factor*rsex + rsex, data = MTPS_orig_DZ)

be_4FE <- lm(behavioral ~ trustbiginterest_scaled + FAMID, data = MTPS_orig_DZ)

#Trust
be_5 <- lm(behavioral ~ trust+ AGE_factor + AGE_factor*rsex+ rsex, data = MTPS_orig_DZ)

be_5FE <- lm(behavioral ~ trust + FAMID, data = MTPS_orig_DZ)


###Turnout

#Trust in government
tu_1 <- lm(overallturnout ~ trustgov_scaled + AGE_factor + AGE_factor*rsex + rsex , data = MTPS_orig_DZ)

tu_1FE <- lm(overallturnout ~ trustgov_scaled + FAMID, data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
tu_2 <- lm(overallturnout ~ trustpol_scaled + AGE_factor + AGE_factor*rsex+ rsex , data = MTPS_orig_DZ)

tu_2FE <- lm(overallturnout ~ trustpol_scaled + FAMID, data = MTPS_orig_DZ)

#Waste taxes
tu_3 <- lm(overallturnout ~ wastetax_scaled + AGE_factor + AGE_factor*rsex+ rsex, data = MTPS_orig_DZ)

tu_3FE <- lm(overallturnout ~ wastetax_scaled + FAMID, data = MTPS_orig_DZ)

#Big interest
tu_4 <- lm(overallturnout ~ trustbiginterest_scaled + AGE_factor + AGE_factor*rsex+ rsex, data = MTPS_orig_DZ)

tu_4FE <- lm(overallturnout ~ trustbiginterest_scaled + FAMID, data = MTPS_orig_DZ)

#Trust
tu_5 <- lm(overallturnout ~ trust+ AGE_factor + AGE_factor*rsex + rsex , data = MTPS_orig_DZ)

tu_5FE <- lm(overallturnout ~ trust + FAMID, data = MTPS_orig_DZ)


```

```{r Appendix Tables A3j and A3l}

stargazer(be_1, be_1FE, be_2, be_2FE, be_3, be_3FE, be_4, be_4FE, type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behavioral_DZ.htm", dep.var.labels = "Behavioral scale")

stargazer(tu_1, tu_1FE, tu_2, tu_2FE, tu_3, tu_3FE, tu_4, tu_4FE, type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Turnout_DZ.htm",  dep.var.labels = "Turnout scale")

```

```{r Figure 4}

#write.csv(coefs, "1 - Tables/discordant_coefficients_MN.csv")

coefs = read.csv("discordant_coefficients.csv") %>% 
  filter(model == "Behavioral")

figure_all = coefs %>% 
  ggplot(
    aes(x = term, y = estimate, colour = effect) 
  ) + 
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
        geom_point(position = position_dodge(width = 1/3), 
                   size = 2) + 
        geom_linerange(aes(x = term, colour = effect,
                     ymin = five_lower,
                     ymax = five_upper),
                   lwd = 1/2, 
                   position = position_dodge(width = 1/3)) + 
    geom_linerange(aes(x = term, colour = effect,
                     ymin = ten_lower,
                     ymax = ten_upper),
                   lwd = 1, 
                   position = position_dodge(width = 1/3)) +
  coord_flip() + 
  ylim(-0.1, 0.4) +
  scale_x_discrete(labels = c("Political trust scale", "Trust in politicians", "Waste taxes")) +
  theme_classic() +
  scale_color_grey() + 
  labs(x = NULL, y = "Standardised estimate", colour = "Effect") +  
  theme(text = element_text(size = 12, family = "serif")) + 
  facet_wrap(Dataset~.)

figure_all

ggsave("1 - Participation_aggregated.png", width = 30, height = 10, units = "cm", plot = figure_all)
ggsave("1 - Participation_aggregated.pdf", width = 30, height = 10, units = "cm", plot = figure_all)

```

```{r Figure 5}

coefs = read.csv("discordant_coefficients.csv") %>% 
  filter(model == "Turnout (National elections)" | model == "Turnout (Presidential)") %>% 
  filter(Dataset != "United States (National, Add. Health)")

figure_all = coefs %>% 
  ggplot(
    aes(x = term, y = estimate, colour = effect) 
  ) + 
  geom_hline(yintercept = 0, colour = gray(1/2), lty = 2) + 
        geom_point(position = position_dodge(width = 1/3), 
                   size = 2) + 
        geom_linerange(aes(x = term, colour = effect,
                     ymin = five_lower,
                     ymax = five_upper),
                   lwd = 1/2, 
                   position = position_dodge(width = 1/3)) + 
    geom_linerange(aes(x = term, colour = effect,
                     ymin = ten_lower,
                     ymax = ten_upper),
                   lwd = 1, 
                   position = position_dodge(width = 1/3)) +
  coord_flip() + 
  ylim(-0.1, 0.4) +
  scale_x_discrete(labels = c("Political trust scale", "Trust in politicians", "Waste taxes")) +
  theme_classic() +
  scale_color_grey() + 
  labs(x = NULL, y = "Standardised estimate", colour = "Effect") +  
  theme(text = element_text(size = 12, family = "serif")) + 
  facet_nested_wrap(Dataset~model)

figure_all

ggsave("4 - Turnout_aggregated.png", width = 30, height = 10, units = "cm", plot = figure_all)
ggsave("4 - Turnout_aggregated.pdf", width = 30, height = 10, units = "cm", plot = figure_all)

```

```{r Models for Appendix Tables A3u and A3w}

###1 - Turnout in 2004 Presidential Election

#Trust in government
t1 <- lm(turnout04 ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t1FE <- lm(turnout04 ~ trustgov_scaled + factor(FAMID), data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
t2 <- lm(turnout04 ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t2FE <- lm(turnout04 ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
t3 <- lm(turnout04 ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t3FE <- lm(turnout04 ~ wastetax_scaled + factor(FAMID), data = MTPS_orig_MZ)

#Big interest
t4 <- lm(turnout04 ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t4FE <- lm(turnout04 ~ trustbiginterest_scaled + FAMID, data = MTPS_orig_MZ)

#Trust 
t5 <- lm(turnout04 ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t5FE <- lm(turnout04 ~ trust + FAMID, data = MTPS_orig_MZ)

###2 - Lifetime Turnout

#Trust in government
t6 <- lm(lifeturnout ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t6FE <- lm(lifeturnout ~ trustgov_scaled + FAMID, data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
t7 <- lm(lifeturnout ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t7FE <- lm(lifeturnout ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
t8 <- lm(lifeturnout ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t8FE <- lm(lifeturnout ~ wastetax_scaled + factor(FAMID), data = MTPS_orig_MZ)

#Big interest
t9 <- lm(lifeturnout ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t9FE <- lm(lifeturnout ~ trustbiginterest_scaled + FAMID, data = MTPS_orig_MZ)

#Trust 
t10 <- lm(lifeturnout ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

t10FE <- lm(lifeturnout ~ trust + FAMID, data = MTPS_orig_MZ)

```

```{r Appendix Tables A3u and A3w}

stargazer(t1, t1FE, t2, t2FE, t3, t3FE, t4, t4FE, t5, t5FE, type = "text",
          omit = c("FAMID", "AGE_factor"), out = "Discordant_Turnout_04.htm")

stargazer(t6, t6FE, t7, t7FE, t8, t8FE, t9, t9FE, t10, t10FE, type = "text",
          omit = c("FAMID", "AGE_factor"), out = "Discordant_Turnout_Lifetime.htm")

```

```{r Models for Appendix Tables A3v and A3x}

###1 - Turnout in 2004 Presidential Election

#Trust in government
t1 <- lm(turnout04 ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t1FE <- lm(turnout04 ~ trustgov_scaled + factor(FAMID), data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
t2 <- lm(turnout04 ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t2FE <- lm(turnout04 ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex+ FAMID, data = MTPS_orig_DZ)

#Waste taxes
t3 <- lm(turnout04 ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t3FE <- lm(turnout04 ~ wastetax_scaled + factor(FAMID), data = MTPS_orig_DZ)

#Big interest
t4 <- lm(turnout04 ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t4FE <- lm(turnout04 ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex+ FAMID, data = MTPS_orig_DZ)

#Trust 
t5 <- lm(turnout04 ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t5FE <- lm(turnout04 ~ trust + FAMID, data = MTPS_orig_DZ)

###2 - Lifetime Turnout

#Trust in government
t6 <- lm(lifeturnout ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t6FE <- lm(lifeturnout ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex+ FAMID, data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
t7 <- lm(lifeturnout ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t7FE <- lm(lifeturnout ~ trustpol_scaled + FAMID, data = MTPS_orig_DZ)

#Waste taxes
t8 <- lm(lifeturnout ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t8FE <- lm(lifeturnout ~ wastetax_scaled + factor(FAMID), data = MTPS_orig_DZ)

#Big interest
t9 <- lm(lifeturnout ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t9FE <- lm(lifeturnout ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex+ FAMID, data = MTPS_orig_DZ)

#Trust 
t10 <- lm(lifeturnout ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

t10FE <- lm(lifeturnout ~ trust + FAMID, data = MTPS_orig_DZ)

```

```{r Appendix Tables A3v and A3x}

stargazer(t1, t1FE, t2, t2FE, t3, t3FE, t4, t4FE, t5, t5FE, type = "text",
          omit = c("FAMID", "AGE_factor"), out = "Discordant_Turnout_04_DZ.htm")

stargazer(t6, t6FE, t7, t7FE, t8, t8FE, t9, t9FE, t10, t10FE, type = "text",
          omit = c("FAMID", "AGE_factor"), out = "Discordant_Turnout_Lifetime_DZ.htm")

```

```{r Models for Appendix Tables A3m, A3o, A3q and A3s}

###1 - Rallies

#Trust in government
b1 <- lm(rally ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_MZ)

b1FE <- lm(rally ~ trustgov_scaled + FAMID, data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
b2 <- lm(rally ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b2FE <- lm(rally ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
b3 <- lm(rally ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_MZ)

b3FE <- lm(rally ~ wastetax_scaled + FAMID, data = MTPS_orig_MZ)

#Big interest
b4 <- lm(rally ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b4FE <- lm(rally ~ trustbiginterest_scaled  + FAMID, data = MTPS_orig_MZ)

#Trust 
b5 <- lm(rally ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b5FE <- lm(rally ~ trust + FAMID, data = MTPS_orig_MZ)

###2 - Worked for Campaign

#Trust in government
b6 <- lm(workpol ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b6FE <- lm(workpol ~ trustgov_scaled + FAMID, data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
b7 <- lm(workpol ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b7FE <- lm(workpol ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
b8 <- lm(workpol ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_MZ)

b8FE <- lm(workpol ~ wastetax_scaled + FAMID, data = MTPS_orig_MZ)

#Big interest
b9 <- lm(workpol ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b9FE <- lm(workpol ~ trustbiginterest_scaled  + FAMID, data = MTPS_orig_MZ)

#Trust 
b10 <- lm(workpol ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b10FE <- lm(workpol ~ trust + FAMID, data = MTPS_orig_MZ)

###3 - Written to Politician

#Trust in government
b11 <- lm(writepol ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b11FE <- lm(writepol ~ trustgov_scaled + FAMID, data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
b12 <- lm(writepol ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b12FE <- lm(writepol ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
b13 <- lm(writepol ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_MZ)

b13FE <- lm(writepol ~ wastetax_scaled + FAMID, data = MTPS_orig_MZ)

#Big interest
b14 <- lm(writepol ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b14FE <- lm(writepol ~ trustbiginterest_scaled  + FAMID, data = MTPS_orig_MZ)


#Trust 
b15 <- lm(writepol ~ trust + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_MZ)

b15FE <- lm(writepol ~ trust + FAMID, data = MTPS_orig_MZ)

###4 - Campaign contribution

#Trust in government
b16 <- lm(donate ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b16FE <- lm(donate ~ trustgov_scaled + FAMID, data = MTPS_orig_MZ)

#Trust in politicians ('crooked')
b17 <- lm(donate ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b17FE <- lm(donate ~ trustpol_scaled + FAMID, data = MTPS_orig_MZ)

#Waste taxes
b18 <- lm(donate ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_MZ)

b18FE <- lm(donate ~ wastetax_scaled + FAMID, data = MTPS_orig_MZ)

#Big interest
b19 <- lm(donate ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_MZ)

b19FE <- lm(donate ~ trustbiginterest_scaled  + FAMID, data = MTPS_orig_MZ)

#Trust 
b20 <- lm(donate ~ trust + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_MZ)

b20FE <- lm(donate ~ trust + FAMID, data = MTPS_orig_MZ)


```

```{r Appendix Tables A3m, A30, A3q and A3s}

stargazer(b1, b1FE, b2, b2FE, b3, b3FE, b4, b4FE, b5, b5FE, 
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_rally.htm")

stargazer(b6, b6FE, b7, b7FE, b8, b8FE, b9, b9FE, b10, b10FE, 
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_workpol.htm")

stargazer(b11, b11FE, b12, b12FE, b13, b13FE, b14, b14FE, b15, b15FE,
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_contactpol.htm")

stargazer(b16, b16FE, b17, b17FE, b18, b18FE, b19, b19FE, b20, b20FE,
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_donation.htm")

```

```{r Models for Appendix Tables A3n, A3p, A3r and A3t}

###1 - Rallies

#Trust in government
b1 <- lm(rally ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_DZ)

b1FE <- lm(rally ~ trustgov_scaled + FAMID, data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
b2 <- lm(rally ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b2FE <- lm(rally ~ trustpol_scaled  + FAMID, data = MTPS_orig_DZ)

#Waste taxes
b3 <- lm(rally ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_DZ)

b3FE <- lm(rally ~ wastetax_scaled + FAMID, data = MTPS_orig_DZ)

#Big interest
b4 <- lm(rally ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b4FE <- lm(rally ~ trustbiginterest_scaled  + FAMID, data = MTPS_orig_DZ)

#Trust 
b5 <- lm(rally ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b5FE <- lm(rally ~ trust + FAMID, data = MTPS_orig_DZ)

###2 - Worked for Campaign

#Trust in government
b6 <- lm(workpol ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b6FE <- lm(workpol ~ trustgov_scaled + FAMID, data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
b7 <- lm(workpol ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b7FE <- lm(workpol ~ trustpol_scaled + FAMID, data = MTPS_orig_DZ)

#Waste taxes
b8 <- lm(workpol ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_DZ)

b8FE <- lm(workpol ~ wastetax_scaled + FAMID, data = MTPS_orig_DZ)

#Big interest
b9 <- lm(workpol ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b9FE <- lm(workpol ~ trustbiginterest_scaled  + FAMID, data = MTPS_orig_DZ)

#Trust 
b10 <- lm(workpol ~ trust + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b10FE <- lm(workpol ~ trust + FAMID, data = MTPS_orig_DZ)

###3 - Written to Politician

#Trust in government
b11 <- lm(writepol ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b11FE <- lm(writepol ~ trustgov_scaled + FAMID, data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
b12 <- lm(writepol ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b12FE <- lm(writepol ~ trustpol_scaled + FAMID, data = MTPS_orig_DZ)

#Waste taxes
b13 <- lm(writepol ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_DZ)

b13FE <- lm(writepol ~ wastetax_scaled + FAMID, data = MTPS_orig_DZ)

#Big interest
b14 <- lm(writepol ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b14FE <- lm(writepol ~ trustbiginterest_scaled + FAMID, data = MTPS_orig_DZ)


#Trust 
b15 <- lm(writepol ~ trust + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_DZ)

b15FE <- lm(writepol ~ trust + FAMID, data = MTPS_orig_DZ)

###4 - Campaign contribution

#Trust in government
b16 <- lm(donate ~ trustgov_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b16FE <- lm(donate ~ trustgov_scaled + FAMID, data = MTPS_orig_DZ)

#Trust in politicians ('crooked')
b17 <- lm(donate ~ trustpol_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b17FE <- lm(donate ~ trustpol_scaled + FAMID, data = MTPS_orig_DZ)

#Waste taxes
b18 <- lm(donate ~ wastetax_scaled + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_DZ)

b18FE <- lm(donate ~ wastetax_scaled + FAMID, data = MTPS_orig_DZ)

#Big interest
b19 <- lm(donate ~ trustbiginterest_scaled + AGE_factor + rsex + AGE_factor*rsex, data = MTPS_orig_DZ)

b19FE <- lm(donate ~ trustbiginterest_scaled  + FAMID, data = MTPS_orig_DZ)

#Trust 
b20 <- lm(donate ~ trust + AGE_factor + rsex + AGE_factor*rsex , data = MTPS_orig_DZ)

b20FE <- lm(donate ~ trust + FAMID, data = MTPS_orig_DZ)


```

```{r Appendix Tables A3n, A3p, A3r and A3t}

stargazer(b1, b1FE, b2, b2FE, b3, b3FE, b4, b4FE, b5, b5FE, 
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_rally_DZ.htm")

stargazer(b6, b6FE, b7, b7FE, b8, b8FE, b9, b9FE, b10, b10FE, 
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_workpol_second_DZ.htm")

stargazer(b11, b11FE, b12, b12FE, b13, b13FE, b14, b14FE, b15, b15FE,
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_contactpol_DZ.htm")

stargazer(b16, b16FE, b17, b17FE, b18, b18FE, b19, b19FE, b20, b20FE,
          type = "text", omit = c("FAMID", "AGE_factor"), out = "Discordant_Behav_donation_DZ.htm")


```

```{r Paternoster test for difference between fixed and individual estimates in main models}

#Behavioral scale models

Z1 = (0.077-0.042)/sqrt(I(0.036)^2+I(0.048)^2)
Z1

#Turnout scale models

Z2 = (0.079-0.023)/sqrt(I(0.036)^2+I(0.049)^2)
Z2

```

